using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

using IllSoft.Xvcc.Volano.Client;

namespace IllSoft.Xvcc.UI
{
    public partial class mainForm : Form
    {
        private Volano.Client.VolanoClient vc;

        public mainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ConnectionArgs ca = new IllSoft.Xvcc.Volano.Client.ConnectionArgs();
            vc = new VolanoClient(ca);

            vc.Connected += new EventHandler(vc_Connected);
            vc.ChannelListReceived += new EventHandler<ChannelListEventArgs>(vc_ChannelListReceived);

            vc.Connect();
        }

        void vc_ChannelListReceived(object sender, ChannelListEventArgs e)
        {
            if (this.InvokeRequired)
            {
                foreach (var item in e.Channels)
                {
                    //this.Invoke((Func<string>)(() => this.listView1.Items.Add(item)));
                    this.Invoke((Func<string, ListViewItem>)this.listView1.Items.Add, item);
                }
            }
            else
            {

            }
        }

        void vc_Connected(object sender, EventArgs e)
        {
            Debug.WriteLine("Connected!");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Channel channel = this.vc.CreateChannel(this.listView1.FocusedItem.Text, new IllSoft.Xvcc.Volano.Client.User(this.textBox1.Text));

            ChannelForm x = new ChannelForm(channel);

            x.Show();
        }
    }
}